//
//  HEOrderTabBarView.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/10/28.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEOrderTabBarView.h"

@interface HEOrderTabBarView ()

@property (nonatomic, strong) UIImageView *selectBtn;
@property (nonatomic, strong) QMUIButton *tobtn;
@property (nonatomic, strong) QMUIButton *agentPayBtn;

@property (nonatomic, assign) BOOL allSelect;
@property (nonatomic, assign) NSInteger total; // 总商品数

@property (nonatomic, strong) UILabel *totalLb; // 合计
@property (nonatomic, strong) UILabel *priceLb; // 总价格
@property (nonatomic, assign) HEOrderTabBarViewType type; // 总商品数

@end

@implementation HEOrderTabBarView

- (instancetype)initWithFrame:(CGRect)frame type:(HEOrderTabBarViewType)type {
    if (self = [super initWithFrame:frame]) {
        _type = type;
        self.backgroundColor = KWhiteColor;
        self.qmui_borderPosition = QMUIViewBorderPositionTop;
        self.qmui_borderWidth = 0.5;
        self.qmui_borderColor = CSplitLineColor;
      
        [self initUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = KWhiteColor;
        self.qmui_borderPosition = QMUIViewBorderPositionTop;
        self.qmui_borderWidth = 0.5;
        self.qmui_borderColor = CSplitLineColor;
      
        _type = HEOrderTabBarViewTypeDefualt;
        [self initUI];
    }
    return self;
}

- (void)initUI {
        
    // 合计
     UILabel *totalLb = [UILabel new];
     _totalLb = totalLb;
     totalLb.text = @"合计：";
     totalLb.font = DYFont(16);
     [self addSubview:totalLb];
    
    _priceLb = [UILabel new];
    _priceLb.text = @"￥0.00";
    _priceLb.font = DYBlodFont(16);
    _priceLb.textColor = CPriceColor;
    [self addSubview:_priceLb];
    
    // 立即支付
    _tobtn = [[QMUIButton alloc] init];
    _tobtn.titleLabel.font = DYBlodFont(16);
    [_tobtn setBackgroundColor:CNavBgColor];
    [_tobtn setTitle:@"立即支付" forState:UIControlStateNormal];
    [_tobtn setTitleColor:KWhiteColor forState:UIControlStateNormal];
    [self addSubview: _tobtn];
    [_tobtn addTarget:self action:@selector(submitOrderClick) forControlEvents:UIControlEventTouchUpInside];
    
    if (_type == HEOrderTabBarViewTypeDefualt) {
        [_tobtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.right.equalTo(self);
            make.width.mas_offset(110);
            make.height.mas_offset(49);
        }];
        [totalLb mas_makeConstraints:^(MASConstraintMaker *make) {
             make.centerY.equalTo(_tobtn);
             make.left.equalTo(self).mas_offset(20);
         }];

        [_priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
             make.centerY.equalTo(_tobtn);
             make.left.equalTo(totalLb.mas_right).mas_offset(0);
             make.right.equalTo(_tobtn.mas_left).mas_offset(-5);
         }];
    }else {
        // 代付
        _agentPayBtn = [[QMUIButton alloc] init];
        _agentPayBtn.titleLabel.font = DYBlodFont(16);
        [_agentPayBtn setBackgroundColor:CPriceColor];
        [_agentPayBtn setTitle:@"找人代付" forState:UIControlStateNormal];
        [_agentPayBtn setTitleColor:KWhiteColor forState:UIControlStateNormal];
        [self addSubview: _agentPayBtn];
        [_agentPayBtn addTarget:self action:@selector(agentPayClick) forControlEvents:UIControlEventTouchUpInside];
        
        [_tobtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.right.equalTo(self);
            make.width.mas_offset(110);
            make.height.mas_offset(49);
        }];
        
        [_agentPayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.right.equalTo(_tobtn.mas_left);
            make.width.mas_offset(110);
            make.height.mas_offset(49);
        }];
     
        [totalLb mas_makeConstraints:^(MASConstraintMaker *make) {
             make.centerY.equalTo(_tobtn);
             make.left.equalTo(self).mas_offset(20);
         }];

        [_priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
             make.centerY.equalTo(_tobtn);
            make.left.equalTo(totalLb.mas_right).mas_offset(0);
             make.right.equalTo(_agentPayBtn.mas_left).mas_offset(-5);
         }];
    }
    
    [totalLb setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
    [_priceLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}

- (void)agentPayClick {
    
}

- (void)submitOrderClick {
    if ([_delegate respondsToSelector:@selector(submitOrderHandler)]) {
        [_delegate submitOrderHandler];
    }
}

- (void)setTotalPrice:(NSString *)totalPrice {
    _totalPrice = totalPrice;
    _priceLb.text = [NSString stringWithFormat:@"￥%@", totalPrice];
}



@end
